﻿using System.Security.Principal;

using SimpleForum.Data.Models;
using SimpleForum.Data.Services;

namespace SimpleForum.Classes.Core.Providers
{
    public class IdentityProvider : IIdentity
    {
        public string AuthenticationType { get; set; }
        public bool IsAuthenticated { get; set; }
        public string Name { get; set; }
        public User User { get; set; }

        public IdentityProvider(string Name, string AuthenticationType, bool IsAuthenticated = true)
        {
            this.Name = Name;
            this.AuthenticationType = AuthenticationType;
            this.IsAuthenticated = IsAuthenticated;

            var User = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance<UserService>().GetUserByEmail(Name);
            if (User != null) this.User = User;
            else this.User = Guest;
        }

        private static User Guest
        {
            get
            {
                return new User() { Id = 0, UserName = "Guest" };
            }
        }
    }
}